<template>
  <div class="login-container">
    <el-card class="login-card" shadow="hover">
      <div slot="header" class="login-header">
        <h2>Login</h2>
      </div>
      <el-form ref="form" :model="form" :rules="rules" @submit.native.prevent="handleLogin">
        <el-form-item prop="username">
          <el-input v-model="form.username" placeholder="Username" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" v-model="form.password" placeholder="Password" prefix-icon="el-icon-lock"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleLogin" class="login-button">Login</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: 'Please input the username', trigger: 'blur' }
        ],
        password: [
          { required: true, message: 'Please input the password', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    handleLogin() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (this.form.username === 'admin' && this.form.password === '123456') {
            this.$router.push('/dashboard');
          } else {
            this.$message.error('Invalid username or password');
          }
        } else {
          console.log('error submit!');
          return false;
        }
      });
    }
  }
};
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, #6e8efb, #a777e3);
}

.login-card {
  width: 400px;
  padding: 20px;
  border-radius: 10px;
  overflow: hidden;
  transition: box-shadow 0.3s;
}

.login-header {
  text-align: center;
  margin-bottom: 20px;
}

.login-header h2 {
  margin: 0;
  color: #333;
}

.el-input {
  margin-bottom: 10px;
}

.login-button {
  width: 100%;
  background-color: #409EFF;
  border-color: #409EFF;
  color: white;
}

.login-button:hover {
  background-color: #66b1ff;
  border-color: #66b1ff;
}
</style>
